import { fetchPeopleInfoList, fetchPeopleInfoDetail, fetchSavePeopleInfo } from '../../fetch/modules/peopleInfo'

const state = {
    peopleLists: {},
    peopleDetail: {},
    saveLeaveInfo: {}
}

const actions = {
    GET_PEOPLE_LISTS: ({ commit, state }, opt) => {
        return fetchPeopleInfoList(opt).then(people => commit('GET_PEOPLE_INFO_LISTS', { people }))
    },
    FETCH_PEOPLE_DETAIL: ({ commit, state }, opt) => {
        return fetchPeopleInfoDetail(opt).then(people => commit('GET_PEOPLE_DETAIL_INFO', { people }))
    },
    FETCT_SAVE_PEOPLE_LEAVE: ({ commit, state }, opt) => {
        return fetchSavePeopleInfo(opt).then(people => commit('SAVE_PEOPLE_LEAVE_INFO', { people }))
    },

}
const mutations = {
    GET_PEOPLE_INFO_LISTS: (state, { people }) => {
        state.peopleLists = people.data;
    },
    GET_PEOPLE_DETAIL_INFO: (state, { people }) => {
        state.peopleDetail = people.data;
    },
    SAVE_PEOPLE_LEAVE_INFO: (state, { people }) => {
        state.saveLeaveInfo = people.data;
    },

}

const getters = {
    getPeopleLists(state) {
        return state.peopleLists;
    },
    getPeopleDetailInfo(state) {
        return state.peopleDetail;
    },
    getSavePeopleLeaveInfo(state) {
        return state.saveLeaveInfo;
    },

}

export default {
    state,
    actions,
    mutations,
    getters
}